package com.rocket.product;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author guoQ.z
 * @date 2021/2/5
 */
@Slf4j
@RestController
public class ProductSendMas {

    @Autowired
    private DefaultMQProducer defaultMqProducer;
    @Autowired
    private RocketMQTemplate rocketMqTemplate;

    @GetMapping("/sendMsg")
    public void sendMsg(String message) {
        try {
            Message message1 = new Message();
            message1.setTopic("practice");
            message1.setTags("");
            message1.setKeys("");
            message1.setBody(message.getBytes());
            defaultMqProducer.send(message1);

//            rocketMqTemplate.convertAndSend("practice", message);
        } catch (Exception ex) {
            log.info("发送失败...");
        }

    }
}
